<template>
  <div>
    <!--<div v-show="!isShowDetail">-->
      <jxf-titletip :title="title" @refreshPage="refreshPage"></jxf-titletip>
      <el-card class="mt20">
        <el-form :inline="true" :model="searchInfo" ref="searchInfo">
          <el-form-item label="流水编号：" prop="tradeNo">
            <el-input v-model="searchInfo.tradeNo" @keyup.enter.native="$refs['telphone'].focus()" clearable></el-input>
          </el-form-item>
          <el-form-item label="供应商账号:" prop="telphone">
            <el-input ref="telphone" v-model="searchInfo.telphone"
                      @keyup.enter.native="$refs['enterpriseName'].focus()" clearable></el-input>
          </el-form-item>
          <el-form-item label="供应商企业名称:" prop="enterpriseName">
            <el-input ref="enterpriseName" v-model="searchInfo.enterpriseName"
                      @keyup.enter.native="$refs['type'].focus()" clearable></el-input>
          </el-form-item>
          <el-form-item label="结算事项:" prop="type">
            <el-select v-model="searchInfo.type" clearable placeholder="全部">
              <el-option ref="status" v-for="item in typeList" :key="item.value" :label="item.label"
                         :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <jxf-Date :startTime.sync="searchInfo.settleStartTime" :endTime.sync="searchInfo.settleEndTime"
                    label="结算时间段："></jxf-Date>
          <el-form-item label="摘要:" prop="transCode">
            <el-select v-model="searchInfo.transCode" clearable placeholder="全部">
              <el-option ref="status" v-for="item in transCodeList" :key="item.value" :label="item.label"
                         :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSearch()">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="info" @click="resetForm('searchInfo')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card class="jxf-table-card mt20">
        <div slot="header" class="clearfix">
          <span>数据列表</span>
          <div>
            <el-button type="primary" @click="exportInfo" :loading="exportLoading">导出</el-button>
          </div>
        </div>
        <jxf-table class="" :table="dataTable">
          <template slot="type" slot-scope="scope">
            <span>{{scope.row.type === 1 ? "入账" : scope.row.type === 2 ? "出账" : ""}}</span>
          </template>
          <template slot="transCode" slot-scope="scope">
            <span>{{scope.row.transCode === 1 ? "订单结算" : scope.row.transCode === 2 ? "转出金额" : scope.row.transCode === 3 ? "转出保理手续费" : scope.row.transCode === 4 ? "转账" : ""}}
            </span>
          </template>
          <!--<template slot="operation" slot-scope="scope">-->
            <!--<el-button type="text" @click="showDetail(scope.row)">查看详情</el-button>-->
          <!--</template>-->
        </jxf-table>
      </el-card>
      <jxf-pagination class="mt20" :pageTotal="pageTotal" :currentPage.sync='currentPage' :pageSize.sync="pageSize"
                      @currentPageChange="currentPageChange" @pageSizeChange="pageSizeChange"></jxf-pagination>
    <!--</div>-->
    <!--<SupplierSettlementAcountFlowDetail ref="SupplierSettlementAcountFlowDetail" v-show="isShowDetail" :isShowDetail.sync="isShowDetail"></SupplierSettlementAcountFlowDetail>-->
  </div>
</template>

<script>
  import formatDate from '@/assets/js/formatDate'
  // import SupplierSettlementAcountFlowDetail from './components/SupplierSettlementAcountFlowDetail'
  export default {
    name: "OrderInfoFeeSettlement",
    // components: {SupplierSettlementAcountFlowDetail},
    data() {
      return {
        title: "供应商结算账户流水",
        typeList: [{
          label: "入账",
          value: 1
        }, {
          label: "出账",
          value: 2
        }],
        transCodeList: [{
          label: "订单结算",
          value: 1
        }, {
          label: "转出金额",
          value: 2
        }, {
          label: "转出保理手续费",
          value: 3
        }, {
          label: "转账",
          value: 4
        }],
        exportLoading: false,
        searchInfoBack: {
          tradeNo: "",
          telphone: "",
          enterpriseName: "",
          type: "",
          settleStartTime: "",
          settleEndTime: "",
          transCode: ""
        },
        searchInfo: {
          tradeNo: "",
          telphone: "",
          enterpriseName: "",
          type: "",
          settleStartTime: "",
          settleEndTime: "",
          transCode: ""
        },
        dataTable: {},
        currentPage: 1,
        pageSize: 10,
        pageTotal: 0,
        // isShowDetail: false
      }
    },
    methods: {
      init() {
        this.dataTable = {
          border: true,
          loading: true,
          tr: [
            {
              id: '1',
              label: '流水编号',
              width: '210',
              prop: 'tradeNo'
            },
            {
              id: '2',
              label: '结算时间',
              width: '160',
              prop: 'createTime'
            },
            {
              id: '3',
              label: '供应商账号',
              width: '120',
              prop: 'telphone'
            },
            {
              id: '4',
              label: '供应商企业名称',
              minWidth: '130',
              prop: 'enterpriseName'
            },
            {
              id: '5',
              label: '结算事项',
              show: 'template',
              prop: 'type'
            },
            {
              id: '6',
              label: '结算金额',
              prop: 'amount'
            },
            {
              id: '7',
              label: '结算后余额',
              minWidth: '100',
              prop: 'newAmount'
            },
            {
              id: '8',
              label: '摘要',
              show: 'template',
              prop: 'transCode'
            }
            // {
            //   id: '12',
            //   label: '操作',
            //   show: 'template',
            //   minWidth: "100",
            //   prop: 'operation',
            //   fixed: "right"
            // }
          ],
          data: []
        }
      },
      getList() {
        let info = formatData.clearObjEmptyPrama({...this.searchInfo, pageSize: this.pageSize, pageNum: this.currentPage})
        ajax.post(apis.factory.getSettleRunningList, info)
          .then(res => {
            if (res.success === true) {
              this.pageTotal = res.data.total
              if (res.data.dataList !== [] && res.data.dataList !== null) {
                this.dataTable.data = this.formatData(res.data.dataList)
              } else {
                this.dataTable.data = []
              }
              this.dataTable.loading = false
            }
          })
      },
      // 列表数据处理
      formatData(list) {
        return list.map(item => {
          return {
            id: item.id,
            tradeNo: item.tradeNo,
            createTime: item.createTime !== null && item.createTime !== "" ? formatDate.timeFormat(item.createTime) : "",
            telphone: item.telphone,
            enterpriseName: item.enterpriseName,
            type: item.type,
            amount: item.amount,
            newAmount: item.newAmount,
            transCode: item.transCode
          }
        })
      },
      // // 查看详情
      // showDetail(row) {
      //   this.isShowDetail = true
      //   this.$refs.SupplierSettlementAcountFlowDetail.getSettleRunningOrderList(row.id)
      // },
      // 导出
      exportInfo(){
        this.exportLoading = true;
        let info = formatData.clearObjEmptyPrama({...this.searchInfo, pageSize: this.pageSize, pageNum: this.currentPage})
        ajax.export(apis.factory.exportSettleRunningList, info)
          .then(res => {
            this.exportLoading = false
          })
      },
      onSearch() {
        this.currentPage = 1
        this.getList()
      },
      // 搜索表单重置
      resetForm(formName) {
        // this.$refs[formName].resetFields();
        this.searchInfo = {...this.searchInfoBack}
      },
      // 切换页面
      currentPageChange(pageNo) {
        this.currentPage = pageNo
        this.getList()
      },
      // 切换页面条数
      pageSizeChange(pageNo) {
        this.pageSize = pageNo
        this.getList()
      },
      // 刷新页面
      refreshPage() {
        this.currentPage = 1
        this.pageSize = 10
        this.searchInfo = {...this.searchInfoBack}
        this.getList()
      }
    },
    created() {
      this.init()
      this.getList()
    }
  }
</script>

<style scoped>

</style>
